
#ifndef PIXMAPAREA_H
#define PIXMAPAREA_H

#include <BSet>
#include <BMap>
#include <BTable>
#include <BScrollArea>
#include <BPixmap>
#include <BImage>
#include <BPainter>
#include <BDrag>

using namespace BWE;

class PixmapArea : public BScrollArea
{
public:
	PixmapArea(BWidget* parent = 0);
	~PixmapArea();

	BPixmap* pixmap() const;

	void enableEvent();
	void disableEvent();
	bool eventEnabled();

	void select(BObject* object);
	void unselect(BObject* object);
	void clearSelection();

protected:
	void adjustArea();
	void applyPartDraging(const BPoint& pos);
	void paintLayout(BWidget* widget, BPainter& painter);
	void paintLayout(BLayout* layout, BPainter& painter);

protected:
	void slotPixmapResized();
	void slotPixmapDirty();
	void slotPixmapFrame();

protected:
	virtual void scrollArea();

protected:
	virtual bool event(const BEvent& event);

	virtual void freshEvent(const BEvent& event);
	virtual void paintEvent(const BEvent& event);

	virtual void keyDownEvent(const BKeyEvent& event);

	virtual void mouseEnterEvent(const BMouseEvent& event);
	virtual void mouseLeaveEvent(const BMouseEvent& event);

	virtual void mousePressEvent(const BMouseEvent& event);
	virtual void mouseReleaseEvent(const BMouseEvent& event);
	virtual void mouseMoveEvent(const BMouseEvent& event);

	virtual void dragEnterEvent(const BDragEvent& event);
	virtual void dragLeaveEvent(const BDragEvent& event);
	virtual void dragMoveEvent(const BDragEvent& event);
	virtual void dragDropEvent(const BDragEvent& event);

private:
	bool				_eventEnabled;
	BPixmapHolder		_pixmap;
	BRect				_area;
	BArray<BRect>		_rects;
	BPoint				_hoverPoint;
	BPoint				_pressPoint;
	BRect				_pressArea;
	BObject*			_hoveredObject;
	BSet<BObject*>		_selectedObjects;
	bool				_dirtySelection;

	bool				_draging;
	Part				_dragPart;
	BMap<PartFlag, BRect>	_dragRectMap;
	BArray<BRect>		_dragInitialRects;

	BDragHolder			_enterDrag;
	BObject*			_enterHoverObject;
	BRect				_enterDragRect;
};

#endif
